package algorithm.dynamic_programming;

public class NQueens {

    public static int num1(int n){
        if(n == 0){
            return 0;
        }
        int[] record = new int[n];
        int i = process(0, record, n);
        return i;
    }

    public static int process(int i, int[] record, int n){
        if(i == n){
            return 1;
        }

        int result = 0;
        for (int j = 0; j < n; j++) {
            record[i] = j;
            if(valid(record, i)){
                result += process(i + 1, record, n);
            }
        }
        return result;
    }

    public static boolean valid(int[] record, int i){
        for (int j = 0; j < i; j++) {
            if(record[i] == record[j] || Math.abs(record[i] - record[j]) == Math.abs(i - j)){
                return false;
            }
        }
        return true;
    }



    public static void main(String[] args) {
        System.out.println(num1(13));
    }
}
